define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/player/index' + location.search,
                    add_url: 'user/player/add',
                    edit_url: 'user/player/edit',
                    del_url: 'user/player/del',
                    multi_url: 'user/player/multi',
                    import_url: 'user/player/import',
                    table: 'player_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'real_name', title: __('Real_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'longitude', title: __('Longitude'), operate: 'LIKE'},
                        {field: 'latitude', title: __('Latitude'), operate: 'LIKE'},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'wechat', title: __('Wechat'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'id_number', title: __('Id_number'), operate: 'LIKE'},
                        {field: 'constellation', title: __('Constellation'), operate: 'LIKE'},
                        {field: 'game_age', title: __('Game_age')},
                        {field: 'status', title: __('Status')},
                        {field: 'projects', title:'项目', operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'video', title: __('Video'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.url},
                        {field: 'video', title: __('Video'), table: table, buttons: [
                                {name: 'sms', title: '视频预览', icon: 'fa fa-file-video-o', classname: 'btn btn-xs btn-primary btn-dialog', url: ''}], operate:false, formatter:
                                function(value,row,index){
                                    return row.video ? "<a href="+row.video
                                        + " class='btn btn-md   btn-success btn-dialog' title='视频预览'>预览</a>" : '';}},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'idcard_img', title: __('Idcard_img'), events: Table.api.events.image, class: 'autocontent', formatter: Table.api.formatter.images},
                        {field: 'is_recommend', title: __('Is_recommend')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'ali_name', title: __('Ali_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'ali_account', title: __('Ali_account'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
